<?php
session_start();
ob_start();
include_once dirname(dirname(__FILE__)) . '/include/common.php';
$core = new core();
$text_search = isset($_POST["text_search"]) ? addslashes(trim($_POST["text_search"])) : 0;
$page = isset($_POST["page"]) ? intval($_POST["page"]) : 1;
$load_more=0;
$customer_list = $core->searchCustomer($text_search,$page,$load_more);
if ($customer_list) {
    $html = '';
    foreach ($customer_list as $customer) {
        switch ($customer->VIP){
            case 0: $vip = "Bình thường";break;
            case 1: $vip = "VIP";break;
            case 2: $vip = "Blacklist";break;
        }
        $html.='<tr>
                    <td>'. $customer->name.'</td>
                    <td class="center">'. $customer->facebook_name.'</td>';
       if($customer->facebook_link!=""){
           $html.=' <td class="center"><a href="'. $customer->facebook_link.'">Link facebook</a></td>';
       }else{
           $html.='<td class="center">Link facebook</td>';
       }
           $html.='<td class="center">'. $customer->phone.'</td>
                    <td class="center">'. $vip.'</td>
                    <td class="center">';
       if ($_SESSION["user_role"] != 3) {
              $html.='<a class="btn btn-info btn_edit_customer" href="addCustomer.php?id='. $customer->customer_id.'" rel="">
                            <i class="icon-edit icon-white"></i>  
                            Edit                                            
                        </a>
                        <a href="javascript:void(0)" class="btn btn-danger btn_delete_customer" rel="'. $customer->customer_id.'">
                            <i class="icon-trash icon-white"></i> 
                            Delete
                        </a>';
        }

          $html.='</td>
                </tr>';
    }
    $page = $page + 1;
    echo json_encode(array('type' => 0, 'html' => $html,'page' => $page, 'load_more' => $load_more));
    die;
} else {
    echo json_encode(array('type' => 1, 'msg' => "Không tìm thấy sản phẩm!"));
    die;
}
?>
